package TankGame5;

public class Shot implements Runnable {//Shot射击子弹
    int x;//子弹的横坐标
    int y;//子弹的纵坐标
    int direct  = 0;//子弹方向
    int speed = 2;//子弹速度
    boolean  islive = true;//子弹是否存活

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (direct){//根据坐标改变子弹的轨迹
                case 0://子弹向下
                    y-=speed;
                    break;
                case 1://向右
                    x+=speed;
                    break;
                case 2://向下
                    y+=speed;
                    break;
                case 3://向左
                    x-=speed;
                    break;
            }
            //当子弹碰到敌人坦克的时候也应该结束线程
            if(!(x>=0&&x<=1000&&y>=0&&y<=750&&islive)){//当子弹到达我们边界的时候，就销毁子弹线程
                islive = false;
                break;
            }
        }
    }
}
